<!--
 * @Author: 生俊甫 1758142861@qq.com
 * @Date: 2024-06-16 14:04:19
 * @LastEditors: 生俊甫 1758142861@qq.com
 * @LastEditTime: 2024-06-17 21:06:40
 * @FilePath: /sjf/2024-project/html_24/wwwroot/html_new/register.html
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>南宁理工学院注册页面</title>
    <link rel="stylesheet" href="../css/Index.css" type="text/css">
    <link rel="stylesheet" href="../css/photoC.css" type="text/css">
</head>
<body>
    <div id="top">
        <img src="../image/Logo.png" class="img1">
        <div class="center">
            <span style="color: blue;font-size: 80px">南</span>
            <span style="color: red;font-size: 80px">宁</span>
            <span style="color: orange;font-size: 80px">理</span>
            <span style="color: blue;font-size: 80px">工</span>
            <span style="color: #00aa00;font-size: 80px">学</span>
            <span style="color: orange;font-size: 80px">院</span>
        </div>
        <div id="top-gov">
            <a href="https://www.bwgl.cn//">南宁理工学院</a>
            &nbsp;&nbsp;&nbsp;&nbsp;
            <a href="http://www.weather.com.cn/weather/101300501.shtml">桂林天气</a>
        </div>
    </div>
    <hr style="height:10px;border:none;border-top:10px groove rgb(14,143, 194);" />
    <h1>注册</h1>
    <div class="login-dialog">
        <div class="row">
            <span>⽤⼾名</span><br>
            <input type="text" id="user_name" name="username"></div>
        <div class="row">
            <span>密   码</span><br>
            <input type="password" id="password" name="password"></div>
        <div class="row">
            <button id="submit" onclick="reg()">提交</button>
        </div>
    </div>
    <p>已有账号?点击 <a href="./login.html">登录</a></p>
    <div id="bottom">
        Copyright © 2021级通信工程一班 生俊甫 21090126. All rights reserved.&nbsp;&nbsp;
        <a href="../html/contactUs.html">联系我们</a>
        <a href="#top">回到顶部</a>
    </div>
    <script src="js/jquery.min.js"></script>
    <script>
        //1. 给按钮添加点击事件，调⽤注册函数
        //2. 封装实现注册函数
        function reg() {
            // 1. 获取两个输⼊框空间中的数据，组织成为⼀个json串
            var reg_info = {
                username: document.getElementById("user_name").value,
                password: document.getElementById("password").value
            };
            console.log(JSON.stringify(reg_info));
            // 2. 通过ajax向后台发送⽤⼾注册请求
            $.ajax({
                url: "/reg",
                type: "post",
                data: JSON.stringify(reg_info),
                success: function (res) {
                    if (res.result == false) {
                        // 4. 如果请求失败，则清空两个输⼊框内容，并提⽰错误原因
                        document.getElementById("user_name").value = "";
                        document.getElementById("password").value = "";
                        alert(res.reason);
                    } else {
                        // 3. 如果请求成功，则跳转的登录⻚⾯
                        alert(res.reason);
                        window.location.assign("/login.html");
                    }
                },
                error: function (xhr) {
                    document.getElementById("user_name").value = "";
                    document.getElementById("password").value = "";
                    alert(JSON.stringify(xhr));
                }
            })
        }
    </script>
</body>
</html>
